package org.jogre.mayi.client;

import java.util.Comparator;

import org.jogre.common.games.Card;

public class CardComparator implements Comparator<Card> {

	public int compare(Card card1, Card card2) {
		int card1Value = getCardValue(card1);
		int card2Value = getCardValue(card2);
		if (card1Value > card2Value)
			return 1;
		else if (card1Value < card2Value)
			return -1;
		else
			return 0;
	}

	public int getCardValue(Card card) {
		int value = 0;
		String cardValue = card.getCard();
		if (Card.JACK.equals(cardValue))
			value += 11;
		else if (Card.QUEEN.equals(cardValue))
			value += 12;
		else if (Card.KING.equals(cardValue))
			value += 13;
		else if (Card.ACE.equals(cardValue))
			value += 14;
		else
			value += card.getValue();

		char cardSuit = card.getSuit();
		if (Card.CLUB == cardSuit)
			value += 15;
		else if (Card.DIAMOND == cardSuit)
			value += 30;
		else if (Card.SPADE == cardSuit)
			value += 45;

		return value;
	}
}
